<?php include_stylesheets_for_form($form) ?>
<?php include_javascripts_for_form($form) ?>
<div class="p15">

        <div id="page-title-div">
        <h1 class="page-title fl"><?php echo $title; ?></h1>
        <div class="fr" >
            <?php if (!$form->getObject()->isNew()): ?>
            <div id="acesso-usuario" align="right" class="p15">
                <a href="<?php echo url_for('@painelcontrole'); ?>">Pesquisar pedido</a>
                |
                <a href="<?php echo url_for('compra/pesquisarPedidoUsuario'); ?>" >Quero ver todos os meus pedidos</a>
            </div>
            <?php endif; ?>
        </div>
            <div class="clearB">
            </div>
        </div>
    <br /><br />
	<form id="form_usuarios" name="form_usuarios" action="<?php echo url_for('formulario/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id_usuario='.$form->getObject()->getIdUsuario() : '')) ?>" method="post" enctype="multipart/form-data">
	<?php if (!$form->getObject()->isNew()): ?>
	<input type="hidden" name="sf_method" value="put" />
	<input type="hidden" name="id_usuario" value="<?php echo $form->getObject()->getIdUsuario() ?>" />
	<?php endif; ?>
		<?php echo $form->renderHiddenFields() ?>
		<?php echo $form->renderGlobalErrors() ?>

		<?php // echo input_hidden_tag('dados_usuario[cliente]', true); ?>
		<span class="warning">Os campos marcados com (*) são obrigatórios.</span>
		<br />
		<div id="dados-usuario" class="curved">
			<div class="title-th">Dados de usuário</div>
			<div class="p15">
				<table class="form_user" >
			    <tbody>
			      <tr>
			        <th class="required"><?php echo $form['username']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['username']; ?>
			        </td>
			       </tr>
			       <tr>
			        <th class="required"><?php echo $form['email']->renderLabel() ?></th>
			        <td>
			          	<?php echo $form['email']->render(); ?>
			        </td>
			       </tr>
			       <tr>
			        <th class="required"><?php echo $form['password']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['password']->render(); ?>
			        </td>
			       </tr>
			       <tr>
			        <th class="required"><?php echo $form['password2']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['password2']->render(); ?>
			        </td>

			      </tr>
		      </tbody>
		      </table>
			</div>
		</div>
		<br />
		<div id="dados-usuario" class="curved">
			<div class="title-th">Dados Pessoais</div>
			<div class="p15">
			    <table class="form_user">
			    <tbody>
			      <tr>
			        <th class="required"><?php echo $form['no_usuario']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['no_usuario']->render(); ?>
			        </td>
			      </tr>
			      <tr>
			        <th><?php echo $form['sobrenome']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['sobrenome']->render(); ?>
			        </td>
			      </tr>
			      <tr>
			        <th class="required"><?php echo $form['nu_cpf']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['nu_cpf'] ?>
			          <?php echo form_error('nu_cpf'); ?>
			        </td>
			      </tr>
			      <tr>
			        <th><?php echo $form['sexo']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['sexo']->render(); ?>
			        </td>
			      </tr>
			      <tr>
			        <th><?php echo $form['dt_nascimento']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['dt_nascimento'] ?>
			          <?php echo form_error('dt_nascimento'); ?>
			        </td>
			      </tr>
			      <tr>
			        <th class="required"><?php echo $form['tel_fixo']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['ddd_tel_fixo'] ?>
			          <?php echo form_error('ddd_tel_fixo'); ?>
			          <?php echo $form['tel_fixo'] ?>
			          <?php echo form_error('tel_fixo'); ?>
			        </td>
			      </tr>
			      <tr>
			        <th><?php echo $form['tel_celular']->renderLabel() ?></th>
			        <td>
			          <?php echo $form['ddd_tel_celular'] ?>
			          <?php echo form_error('ddd_tel_celular'); ?>
			          <?php echo $form['tel_celular'] ?>
			          <?php echo form_error('tel_celular'); ?>
			        </td>
			      </tr>
		      </tbody>
		      </table>
	      </div>
      </div>
      <br />
		<div id="dados-usuario" class="curved">
			<div class="title-th">Dados Residenciais</div>
			<div class="p15">
              <?php if ($form->getObject()->isNew()): ?>
	      <table>
	      <tbody>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['nu_cep']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['nu_cep'] ?>
		          <?php echo form_error('nu_cep'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['logradouro']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['logradouro'] ?>
		          <?php echo form_error('logradouro'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['logradouro_numero']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['logradouro_numero'] ?>
		          <?php echo form_error('logradouro_numero'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th><?php echo $form['endereco']['logradouro_complemento']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['logradouro_complemento'] ?>
		          <?php echo form_error('logradouro_complemento'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['cidade']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['cidade'] ?>
		          <?php echo form_error('cidade'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['bairro']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['bairro'] ?>
		          <?php echo form_error('bairro'); ?>
		        </td>
		      </tr>
		      <tr>
		        <th class="required"><?php echo $form['endereco']['sg_uf']->renderLabel() ?></th>
		        <td>
		          <?php echo $form['endereco']['sg_uf']->render() ?>
		          <?php echo form_error('sg_uf'); ?>
		        </td>
		      </tr>
		    </tbody>
		  </table>
                            <?php else: ?>
                        <div id="enderecos_usuario">
                                <?php include_component('usuarios', 'endereco', array('is_checkable'=> false)); ?>
                        </div>
                            <?php endif; ?>
		  </div>
	</div>

	<br />
	<?php
		comandos_form(
			null,
			submit_tag('Salvar', array('class'=>'bt-comprar curved'))
		);
	?>
	</form>
</div>
<script>
    $(function()
        {

	        <?php //if($form['endereco']['nu_cep']->getValue() != "") : ?>
	        	//System.loaddata.jsonCEP(null, "#dados_usuario_endereco_nu_cep", '<?php //echo url_for('foxsis/buscaPorCep') ?>');
	        <?php //endif; ?>
	        System.formdata.calendar({changeMonth: true,changeYear: true, yearRange: '1960:<?php echo date("Y"); ?>', maxDate: 0});
	        System.formdata.mask('#dados_usuario_endereco_nu_cep', 'cep');
	        System.formdata.mask('#dados_usuario_nu_cpf', 'cpf');
	        System.loaddata.jsonCEP("busca-cep", "#dados_usuario_endereco_nu_cep");
            System.formdata.save(new Array("msgAlerta", "Atenção:"));
        }
    );
</script>